<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="user"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>商家列表</legend>
            </fieldset>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
            <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex"
              :fbtn="btn"></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../../common/pagetop.vue";
import Secondnav from "../../common/secondnav.vue";
import Tables from "../../common/tables.vue";
import Search from "../../common/search.vue";
export default {
  name: "shoplist",
  components: { Pagetop, Secondnav, Tables, Search },
  data () {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      type: localStorage.getItem("type")
    };
  },
  mounted () {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/shop/aapi/v1.9/dealers";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          "type.in":"SOLO,CHAIN",
          sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          if(res[i].val){
          dates[res[i].key + '.equals'] = res[i].val;
         }
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          "type.in":"SOLO,CHAIN",
          sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "商家ID" },
          { field: "accountName", title: "商家名称" },
          {field: "mobile",title: "联系方式"},
          {field: "realName",title: "真实姓名"},
          {field: "type",title: "类型",
          	templet: function (d) {
             if(d.type=='SOLO'){
             	return '个体商家'
             }
             else{
             	return '连锁商家'
             }
            }
          },
          {
            field: "status",
            title: "状态",
            templet: function (d) {
              if (d.status == "ENABLE") return "启用";
              else return "禁用";
            }
          },
          
          {
            field: "createAt",
            title: "创建时间",
            templet: function (d) {
              return FormatDate(d.createAt);
            }
          },
          {
            field: "right",
            title: "操作",
            fixed: "right",
            templet: function (d) {
              var str ='<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">设置pv总值</a>';
              str=str+'<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="enable">WUC/积分比例设置</a>';
              return str;
            }
          }
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page+1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "mobile", title: "商家手机号", type: "input" },{ field: "accountName", title: "账号", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    detailInfo: function(data) {
    	var _this=this;
    	var url='/profit/aapi/v1.9/platformp-rofit?createId.equals=1&dealerId.equals='+data.id+"&page=0&size=20"
    	ajaxRequest(url, "GET", "JSON", '', function (ret, err) {
    			var red=ret.data.list;
    			if(red&&red.length>0){
    				var str=red[0].amountlimit
    			}
    			else{
    				var str=""
    			}
    			
    		layer.prompt({title: '设置'+data.accountName+'pv总值，百分比',formType:0}, function(value, index){
    			
    			var url1="/profit/aapi/v1.9/platformp-rofit"
    			var method='POST'
    			var dates={
    				amountlimit:value,
    				dealerId:data.id,
    				"settingType": "UNIFIED"
    			}
    			if(red&&red.length>0){
    				dates.id=red[0].id
    				method='PUT'
    			}
    			ajaxRequest(url1, method, "json", dates, function (res, errs) {
    				layer.msg('操作成功');
    				layer.close(index);
    			})
			 		
				});
				$(".layui-layer-content .layui-layer-input").val(str)
    	})
     	
    },
    enableInfo:function(data){
    	var _this=this;
    	var url='/pay/aapi/v1.9/dealer-withdrawal-setting/findDealer/'+data.id
    	ajaxRequest(url, "GET", "JSON", '', function (ret, err) {
    			if(ret.data&&ret.data.balanceCreditRmbRatio){
    				var str=ret.data.balanceCreditRmbRatio
    			}
    			else{
    				var str=""
    			}
    			
    		layer.prompt({title: '设置'+data.accountName+'比例设置',formType:0}, function(value, index){
    			
    			var url1="/pay/aapi/v1.9/dealer-withdrawal-setting"
    			var method='POST'
    			var dates={
    				balanceCreditRmbRatio:value,
    				dealerId:data.id
    			}
    			ajaxRequest(url1, method, "json", dates, function (res, errs) {
    				layer.msg('操作成功');
    				layer.close(index);
    			})
			 		
				});
				$(".layui-layer-content .layui-layer-input").val(str)
    	})
    },
    screens: function () {
      return screen();
    }
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  }
};
</script>
<style scoped>
/**/
</style>
